﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using CommandLine;
using Newtonsoft.Json;

namespace my_console
{
  class Program2
  {
    // static void Main(string[] args)
    // {

    //   Parser.Default.ParseArguments<Options>(args)
    //         .WithParsed(RunOptions)
    //         .WithNotParsed(_ => { Environment.ExitCode = 1; });
    // }


    static void RunOptions(Options option)
    {
			System.Console.WriteLine(JsonConvert.SerializeObject(option));
    }

  }


  // Define a class to receive parsed values
  public class Options
  {
    [Option('s', "server", Required = true, HelpText = "server address to install database")]
    public string Server { get; set; }

    [Option('l', "language", Default = "zh-cn", Required = false,
        HelpText = "language for database.(zh-cn/en-us)")]
    public string Language { get; set; }

    [Option('u', "userid", Required = true, HelpText = "user id for database connection string")]
    public string UserId { get; set; }

    [Option('p', "password", Required = true, HelpText = "password for database connection string")]
    public string Password { get; set; }

    [Option('f', "folder", Required = false, HelpText = "folder for database physical files")]
    public string Folder { get; set; }

    [Option('d', "domain", Default = "miPlatform_Domain", Required = false, HelpText = "domain database name")]
    public string DomainDbName { get; set; }

    [Option('i', "audit", Default = "miPlatform_Audit", Required = false,
        HelpText = "audit database name")]
    public string AuditDbName { get; set; }

    [Option('t', "timeout", Required = false, HelpText = "database connection timeout in seconds")]
    public int DatabaseTimeout { get; set; } = 500;


    public string ConnectionString()
    {
      var connString =
        $"Password={Password};Persist Security Info=True;User ID={UserId};Initial Catalog=master;"
        + $"Data Source={Server};MultipleActiveResultSets=True;Connection Timeout={DatabaseTimeout}";

      return connString;
    }

    //[HelpOption]
    //public string GetUsage()
    //{
    //    return HelpText.AutoBuild(this, (HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current));
    //}
  }

}
